home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BCI NET
/
BCI NET Dec 94.iso
/
archives
/
telecomm
/
bbs
/
wwbbs.lha
/
WWBBS
/
Programming
/
Lib
/
wwbbs_lib.c
Wrap
C/C++ Source or Header
|
1994-09-23
|
5KB
|
248 lines
#include <exec/types.h>
#include <exec/exec.h>
#include <libraries/wwbbs.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/wwbbs.h>
BOOL Ask(BYTE *prompt,BOOL def)
{
BOOL ret=FALSE,kg=TRUE;
if(prompt)
printf("~p\n%s (%s,%s)? ",prompt,(def) ? "[Y]" : "Y",(def) ? "N" : "[N]");
{
int c;
while(kg)
{
c=getchar();
if(c==EOF)
break;
switch(c)
{
case '\r':
ret=def;
kg=FALSE;
break;
case 'Y':
case 'y':
ret=TRUE;
kg=FALSE;
break;
case 'N':
case 'n':
ret=FALSE;
kg=FALSE;
break;
}
}
}
if(!kg)
{
if(ret)
printf("~iYes\n");
else
printf("~iNo\n");
}
return(ret);
}
BOOL GetLine(BYTE *id,BYTE *buff,UWORD length,ULONG flags)
{
BOOL ret=FALSE;
UWORD index=0;
printf("~i");
if(flags & GLFLG_Edit)
{
index=strlen(buff);
buff[index]=NULL;
printf(buff);
}
else
strcpy(buff,"");
{
BOOL kg=TRUE;
int c;
while(kg)
{
c=getchar();
if(c==EOF)
break;
switch(c)
{
case '\b':
if(index)
{
index--;
buff[index]=NULL;
printf("\b \b");
}
break;
case '\r':
if( !( !index && (flags & GLFLG_NoEmpty) ) )
{
printf("\n");
if(index)
ret=TRUE;
kg=FALSE;
}
break;
default:
if(isprint(c) && index<length)
{
if(flags & GLFLG_Format)
{
if(isalpha(c))
{
if( (index && !isalpha(buff[index-1])) || !index)
c=toupper(c);
else
c=tolower(c);
}
}
if(flags & GLFLG_ToLower)
{
if(isalpha(c))
c=tolower(c);
}
if(flags & GLFLG_ToUpper)
{
if(isalpha(c))
c=toupper(c);
}
if(flags & GLFLG_Chars)
{
if(!isalpha(c))
c=NULL;
}
if(flags & GLFLG_Digits)
{
if(!isdigit(c))
c=NULL;
}
if(flags & GLFLG_NoChars)
{
if(isalpha(c))
c=NULL;
}
if(flags & GLFLG_NoDigits)
{
if(isdigit(c))
c=NULL;
}
if(flags & GLFLG_NoSpaces)
{
if(isspace(c))
c=NULL;
}
if(flags & GLFLG_NoPunct)
{
if(ispunct(c))
c=NULL;
}
if(flags & GLFLG_BeginChar)
{
if(!index && !isalpha(c))
c=NULL;
}
if(flags & GLFLG_BeginDigit)
{
if(!index && !isdigit(c))
c=NULL;
}
if(c)
{
sprintf(&buff[strlen(buff)],"%c",c);
index++;
if(flags & GLFLG_NoEcho)
printf(".");
else
printf("%c",c);
}
}
break;
}
{
BOOL pagereceived=FALSE;
GetStatusTags(STTAG_Name,id,STTAG_PageReceived,&pagereceived,TAG_END);
if(pagereceived)
{
printf("~i%s",buff);
SetStatusTags(STTAG_Name,id,STTAG_PageReceived,FALSE,TAG_END);
}
}
}
}
return(ret);
}
void ShowText(BYTE *file)
{
BYTE rows[4];
strcpy(rows,"");
if(GetVar("ROWS",rows,3,NULL)!=-1)
{
FILE *fp;
int count=0;
printf("~o");
if(fp=fopen(file,"r"))
{
BYTE buff[256];
while(fgets(buff,255,fp))
{
if(WaitForChar(Input(),0))
{
getchar();
break;
}
if(count==atoi(rows)-1)
{
printf("~pMore ([Y],N)? ");
if(!Ask(NULL,TRUE))
break;
}
printf(buff);
count++;
}
fclose(fp);
}
}
}
BOOL RunEditor(BYTE *filename)
{
BOOL ret=FALSE;
BYTE editor[256];
strcpy(editor,"");
if(GetVar("EDITOR",editor,255,NULL)!=-1)
{
if(strlen(editor))
{
BYTE cmd[256];
sprintf(cmd,"%s \"%s\"",editor,filename);
printf("~r");
SetMode(Input(),0);
SystemTags(cmd,TAG_END);
SetMode(Input(),1);
{
FILE *fp;
if(fp=fopen(filename,"r"))
{
fclose(fp);
if(Ask("Save message",TRUE))
ret=TRUE;
else
DeleteFile(filename);
}
}
}
else
printf("~s\nPlease select an editor first.\n");
}
return(ret);
}